package com.epfresh.bean;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by wzh on 16-10-18.
 */
public class CityAddress {

    private List<Address> deliveryAddress;
    private ArrayList<HomeCity> cityList;

    public ArrayList<HomeCity> getCityList() {
        return cityList;
    }

    public void setCityList(ArrayList<HomeCity> cityList) {
        this.cityList = cityList;
    }

    //    private List<HomeCity> cityList;
    //private City city;

    private String result;

    public List<Address> getDeliveryAddress() {
        return deliveryAddress;
    }

    public void setDeliveryAddress(List<Address> deliveryAddress) {
        this.deliveryAddress = deliveryAddress;
    }

//    public List<HomeCity> getCityList() {
//        return cityList;
//    }
//
//    public void setCityList(List<HomeCity> cityList) {
//        this.cityList = cityList;
//    }


/*
    public City getCity() {
        return city;
    }

    public void setCity(City city) {
        this.city = city;
    }
*/

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public String getCityId(String cityName, String province) {

        if (((cityName != null && !"".equals(cityName)) || (province != null && !"".equals(province))) && cityList != null) {
            //ArrayList<HomeCity> cityList = city.getCityList();

            if (cityList != null) {
                for (int i = 0; i < cityList.size(); i++) {
                    HomeCity homeCity = cityList.get(i);
                    if (homeCity != null && cityName != null && cityName.equals(homeCity.getName())) {
                        String code = homeCity.getCode();
                        return code;
                    }
                }
                for (int i = 0; i < cityList.size(); i++) {
                    HomeCity homeCity = cityList.get(i);
                    if (homeCity != null && province != null && province.equals(homeCity.getName())) {
                        String code = homeCity.getCode();
                        return code;
                    }
                }
            }
        }

        return null;
    }

    public void getCityBoxMaker(List<CityAddressBox> list, CityAddressBox locationBox, boolean isAddress, String addressId, String cityId) {
        if (list == null) {
            return;
        }
        list.clear();
        boolean isSelect = false;
        //type == 0(当前收货地址名称),1(地址item),2(开通城市),3(具体城市)
        if (isAddress && deliveryAddress != null && deliveryAddress.size() > 0) {
            CityAddressBox cb = new CityAddressBox();
            cb.setType(0);
            list.add(cb);
            for (int i = 0; i < deliveryAddress.size(); i++) {
                Address address = deliveryAddress.get(i);
                CityAddressBox cab = new CityAddressBox();
                cab.setType(1);
                cab.setAddress(address);
                if (addressId != null && !"".equals(addressId) && address != null && addressId.equals(address.getId())) {
                    address.setSelect(true);
                    isSelect = true;
                }
                list.add(cab);
            }
        }


        locationBox.setType(2);
        list.add(locationBox);
        if (cityList != null) {
            //List<HomeCity> cityList = city.getCityList();
            if (cityList != null) {
                int size = cityList.size();
                for (int i = 0; i < size; i += 3) {
                    CityAddressBox cab = new CityAddressBox();
                    cab.setType(3);

                    list.add(cab);
                    List<HomeCity> hcs = new ArrayList<>();

                    cab.setCityList(hcs);
                    HomeCity hc = cityList.get(i);
                    hcs.add(hc);
                    if (!isSelect && cityId != null && !"".equals(cityId) && hc != null && cityId.equals(hc.getCode())) {
                        hc.setSelect(true);
                    }
                    if (i + 1 < size) {
                        hc = cityList.get(i + 1);
                        hcs.add(hc);
                        if (!isSelect && cityId != null && !"".equals(cityId) && hc != null && cityId.equals(hc.getCode())) {
                            hc.setSelect(true);
                        }
                    }
                    if (i + 2 < size) {
                        hc = cityList.get(i + 2);
                        hcs.add(hc);
                        if (!isSelect && cityId != null && !"".equals(cityId) && hc != null && cityId.equals(hc.getCode())) {
                            hc.setSelect(true);
                        }
                    }
                }
            }
        }
    }
}
